﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using LP580.CG;

public partial class CompanyList : System.Web.UI.Page
{

    private int CurrentClassID = Utils.RQ_int("c");
    private int pageindex = Utils.RQ_int("pi");

    private int OrderType = Utils.RQ_int("od");
    private int AreaId = Utils.RQ_int("at");

    private int pagesize = 12;
    protected void Page_Load(object sender, EventArgs e)
    {


        bindCompanyClassList();

        //筛选条件
        bindConditions();

        //公司列表
        bindCompanyList();
    }

    private void bindCompanyClassList()
    {
        StringBuilder sbHtml = new StringBuilder();
        sbHtml.AppendLine("<table width='100%' border='0' cellpadding='0' cellspacing='0'>");
        List<clsCompanyClass> ls = clsCompanyClass.GetClass();
        int i = 0;
        foreach (clsCompanyClass cc in ls)
        {
            i++;
            sbHtml.Append(string.Format("<tr><td class='{0}'><a href='CompanyList.aspx?od={1}&c={2}'>{3}</a></td></tr>", i % 2 == 0 ? "cjleftmenu" : "cjleftmenu1", OrderType, cc.CompanyClassCode, cc.CompanyClassName));
        }
        sbHtml.AppendLine("</table>");
        ltCompanyClassList.Text = sbHtml.ToString();
    }

    private void bindConditions()
    {
        StringBuilder sbHtml = new StringBuilder();

        sbHtml.AppendLine("<table width='794' border='0' cellpadding='0' cellspacing='0' class='mtop10'>");
        sbHtml.AppendLine("<tr>");
        sbHtml.AppendLine("<td width='61' align='left' class='bottomline'>排列方式：</td>");
        string url = "CompanyList.aspx?c=" + CurrentClassID + "&od=0&at=" + AreaId;
        sbHtml.AppendLine("<td width='66' align='left' class='bottomline'><a href='"+url+"'><img src='images/lrl.gif' width='58' height='20'></a></td>");
        url = "CompanyList.aspx?c=" + CurrentClassID + "&od=1&at=" + AreaId;
        sbHtml.AppendLine("<td width='69' align='left' class='bottomline'><a href='" + url + "'><img src='images/jrtime.gif' width='69' height='20'></a></td>");
        sbHtml.AppendLine("<td width='131' align='right' class='bottomline'><select name='select2'>");
        sbHtml.AppendLine("<option>店铺所在地</option>");
        sbHtml.AppendLine("</select></td>");
        sbHtml.AppendLine("<td width='139' align='left' class='bottomline'>&nbsp;</td>");
        sbHtml.AppendLine(string.Format("<td align='right' class='bottomline'>{0}共有<span class='membername'>{1}个</span>品牌厂家</td>", clsCompanyClass.GetClassNameByCode(CurrentClassID), clsUserCompanyInfo.GetCountByCode(CurrentClassID)));
        sbHtml.AppendLine("</tr>");
        sbHtml.AppendLine("</table>");

        ltConditions.Text = sbHtml.ToString();
    }

    private void bindCompanyList()
    {
        StringBuilder sbHtml = new StringBuilder();

        List<clsUserCompanyInfo> ls = clsUserCompanyInfo.GetCollection(2, CurrentClassID, OrderType, AreaId);

        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = ls;
        pds.PageSize = pagesize;
        pds.CurrentPageIndex = (pageindex - 1 < 0) ? 0 : (pageindex - 1);
        pds.AllowPaging = true;

        foreach (clsUserCompanyInfo com in pds)
        {
            sbHtml.Append(getCompanyUnit(com));
        }
        ltCompanyList.Text = sbHtml.ToString();

        string baseUrl = "CompanyList.aspx?c=" + CurrentClassID + "&od=" + OrderType + "&at=" + AreaId;

        ltPage.Text = LvEasyPager.CreateUser(baseUrl + "&", pageindex, pagesize, ls.Count);
    }

    private string getCompanyUnit(clsUserCompanyInfo cls)
    {
        StringBuilder sbHtml = new StringBuilder();

        sbHtml.AppendLine("<table width='794' border='0' cellpadding='0' cellspacing='0' class='mtop10 cjlistbg'>");
        sbHtml.AppendLine("        <tr>");
        sbHtml.AppendLine("          <td class='cjpd20'><table width='100%' border='0' cellspacing='0' cellpadding='0'>");
        sbHtml.AppendLine("              <tr>");
        sbHtml.AppendLine("                <td width='26%' height='152' valign='top'><table width='160' border='0' cellspacing='0' cellpadding='0'>");
        sbHtml.AppendLine("                  <tr>");
        sbHtml.AppendLine(string.Format("                    <td height='91' valign='top'><a href='Company.aspx?id={0}'><img src='/{1}' width='156' height='78' class='cjlogoboder' /></a></td>", cls.UserID, cls.CompanyLogo));
        sbHtml.AppendLine("                  </tr>");
        sbHtml.AppendLine("                  <tr>");
        sbHtml.AppendLine(string.Format("                    <td height='46' align='left' class='cjline'>主营产品：{0}</td>", cls.SalesItem));
        sbHtml.AppendLine("                  </tr>");
        sbHtml.AppendLine("                </table>");
        sbHtml.AppendLine("                  </td>");
        sbHtml.AppendLine("                <td width='3%' align='center' valign='middle'><img src='images/sliao.gif' width='16' height='152'></td>");
        sbHtml.AppendLine("                <td width='30%' align='center' valign='top'><table width='90%' border='0' cellspacing='0' cellpadding='0'>");
        sbHtml.AppendLine("                  <tr>");
        sbHtml.AppendLine(string.Format("                    <td height='26' align='left' class='cjname'>{0}</td>", cls.CompanyName));
        sbHtml.AppendLine("                  </tr>");
        sbHtml.AppendLine("                  <tr>");
        sbHtml.AppendLine(string.Format("                    <td height='26' align='left'>展厅人气：<span class='caigoujia'>{0}</span></td>", cls.ViewCount));
        sbHtml.AppendLine("                  </tr>");
        sbHtml.AppendLine("                  <tr>");
        sbHtml.AppendLine(string.Format("                    <td height='26' align='left'>联系人：{0}</td>", cls.ContactPerson));
        sbHtml.AppendLine("                  </tr>");
        sbHtml.AppendLine("                  <tr>");
        sbHtml.AppendLine(string.Format("                    <td height='26' align='left'>电话：{0}</td>", cls.Tel));
        sbHtml.AppendLine("                  </tr>");
        sbHtml.AppendLine("                  <tr>");
        sbHtml.AppendLine("                    <td><table width='100%' border='0' cellspacing='0' cellpadding='0'>");
        sbHtml.AppendLine("                        <tr>");
        sbHtml.AppendLine("                          <td width='40%' height='38' align='left'><img src='images/wyzx.gif' width='69' height='20'></td>");
        sbHtml.AppendFormat("                          <td width='29%' align='left'><a href='javascript:addFav(\"c\",{0})'><img src='images/sc2.gif' width='47' height='20'></a></td>",cls.UserID);
        sbHtml.AppendLine(string.Format("                          <td width='31%' align='left'><a href='Company.aspx?id={0}'><img src='images/jr.gif' width='47' height='20' /></a></td>", cls.UserID));
        sbHtml.AppendLine("                        </tr>");
        sbHtml.AppendLine("                    </table></td>");
        sbHtml.AppendLine("                  </tr>");
        sbHtml.AppendLine("                </table></td>");
        sbHtml.AppendLine("                <td width='3%' align='center' valign='middle'><img src='images/sliao.gif' width='16' height='152'></td>");
        sbHtml.AppendLine("                <td width='38%' align='right' valign='top'><table width='100%' border='0' cellspacing='0' cellpadding='0'>");
        sbHtml.AppendLine("                  <tr>");

        List<clsGiftProduct> lsPro = clsGiftProduct.GetCollection(2, cls.UserID);
        foreach (clsGiftProduct pro in lsPro)
        {
            sbHtml.AppendLine(string.Format("                    <td height='112' align='center' valign='top'><a href='Gift.aspx?id={0}'><img src='/{1}' width='94' height='94' class='proboder'></a><div style='margin:5px 0;'>{2}</div><div style='margin:5px 0;'>采购价：<span class='caigoujia'>￥{3}</span></div></td>", pro.GiftProductID, pro.GiftProductPic, pro.GiftProductName, pro.GiftProductPriceSpanName));
        }

        sbHtml.AppendLine("                  </tr>");
        sbHtml.AppendLine("                </table></td>");
        sbHtml.AppendLine("              </tr>");
        sbHtml.AppendLine("            </table></td>");
        sbHtml.AppendLine("        </tr>");
        sbHtml.AppendLine("      </table>");


        return sbHtml.ToString();
    }



}